/*
	jGrouse framework
	Copyright 2007 by Denis Riabtchik 
	All rights reserved.
	
	Licensed under modified BSD license. See license.txt for details
*/

/**
	@module jgrouse.widgets.Radiobutton
	@requires jgrouse.widgets.InputControl
*/

jgrouse.module(
{
	name : 'jgrouse.widgets.Radiobutton',
	requires : ['jgrouse.widgets.InputControl'],
	body : function(embed)
	{
		eval(embed);
		
		jgrouse.widgets.registerWidget('radio', 'jgrouse.widgets.Radiobutton');
		
		/**
			Widget implementing radiobutton. Equivalent to &lt;input type='radio'&gt; control.
			@class jgrouse.widgets.Radiobutton
			@extends jgrouse.widgets.InputControl
		*/
		jgrouse.define('jgrouse.widgets.Radiobutton', 'jgrouse.widgets.InputControl', function(embed)
		{
			eval(embed);
			
			return {
				/**
					@constructor initialize
					@inheritdesc
				*/
				initialize : function(option, styles)
				{
					_super(this, 'initialize', option, styles);
					this.setAttribute('type', 'radio');
					this.enableEvent('click');
				},
				
				/**
					Set model's value. If given value equals to radiobutton's <b>value</b> property, then the 
					radiobutton would become checked. 
					@function setModelValue
					@param {Object} value - value to set
				*/
				setModelValue : function(value)
				{
					var v = this.getValue();
					this.setAttribute('checked', v == value);
				},
				
				/**
					Event handler for onClick - fires changed <b>modelValue</b> property depending if the box becomes 
					checked or unchecked.
					@function onClick
					@param {DOMEvent} event - event that triggered processing
					@see setModelValue
				*/
				onClick : function(event)
				{
					this.setAttribute('checked', true);
					this.firePropertyChange('modelValue', this.getValue());
				}				
			}
		});
	}
});